package com.moduleSys.cms.menu;

import com.moduleSys.entity.system.Menu;
import com.moduleSys.entity.system.MenuVo;
import com.moduleSys.menuService.MenuService;
import com.moduleSys.utils.json.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by czw on 2017/7/19 0019.
 */
@RestController
@RequestMapping(value = "/menu")
public class MenuController {
    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);

    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/addMenu",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult addUser(Menu resources){
       menuService.insert(resources);
        return new JsonResult(1,null,null);
    }

    @RequestMapping(value = "/list",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult list(Integer pageSize,Integer currentPage,String name){
        JsonResult jr = menuService.selectByMap(pageSize, currentPage, name);
        return jr;
    }
    @RequestMapping(value = "/getMenuByRoleId",method = {RequestMethod.GET,RequestMethod.POST})
    public List<Menu> getMenuByRoleId(Long id){
        List<Menu> list = menuService.getMenuByRoleId(id);
        return list;
    }
    @RequestMapping(value = "/getMenu",method = {RequestMethod.GET,RequestMethod.POST})
    public List<MenuVo> getAuthorizationMenu(){
        List<MenuVo> list = menuService.getAuthorizationMenu();
        return list;
    }
    @RequestMapping(value = "/deleteBatch",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteBatch(@RequestParam(value = "itemIds[]",required = false) Long[] itemIds){
        return menuService.deleteBatch(itemIds);
    }

    @RequestMapping(value = "/updateMenu",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult updateMenu(Menu menu){
        return menuService.updateMenu(menu);
    }
}
